#include "widget.h"
#include "ui_widget.h"
#include <QSettings>
#include <QDebug>
 QSettings settings("MySoft", "Star Runner");
Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    QStringList items;
    QStringList items2;
    items <<"name" << "sex" << "moneny";
    items2 << "1 " << "2" <<"3";
    ui->comboBox->addItems(items);
    ui->comboBox_2->addItems(items2);
    recData(); //恢复上次关闭时的界面
}

Widget::~Widget()
{
    storeData();//页面关闭时保存数据
    delete ui;
}

void Widget::storeData(){
    settings.setValue("combobox",ui->comboBox->currentIndex());
    settings.setValue("comboBox_2",ui->comboBox_2->currentIndex());
    settings.setValue("lineEdit",ui->lineEdit->text());
    settings.setValue("spinbox",ui->spinBox->value());
}
void Widget::recData(){
    ui->comboBox->setCurrentIndex( (settings.value("combobox").toInt()));
    ui->comboBox_2 ->setCurrentIndex( (settings.value("comboBox_2").toInt()));
    ui->lineEdit->setText( (settings.value("lineEdit")).toString());
    ui->spinBox->setValue( (settings.value("spinbox")).toInt());
}


